package io.zhoujie.modules.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.zhoujie.common.utils.PageUtils;
import io.zhoujie.common.utils.R;
import io.zhoujie.modules.admin.entity.ActiveEntity;
import io.zhoujie.modules.admin.entity.AppUserEntity;
import io.zhoujie.modules.admin.service.ActiveService;
import io.zhoujie.modules.app.utils.SensitiveWordChecker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 管理端——活动管理
 *
 * @author zhoujie
 * @email 813685764@qq.com
 * @date 2024-02-20 12:10:43
 */
@RestController
@Api(tags = "管理端——活动管理")
@RequestMapping("/admin/active")
public class ActiveController {
    @Autowired
    private ActiveService activeService;

    /**
     * 活动列表
     *
     * @param params
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("活动列表")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = activeService.queryPage(params);

        return R.ok().put("page", page);
    }

    @GetMapping("/info/{aid}")
    @ApiOperation("分类详情")
    public R info(@PathVariable("aid") Integer aid) {
        ActiveEntity active = activeService.getById(aid);

        return R.ok().put("active", active);
    }

    @PostMapping("/update")
    @ApiOperation("活动修改")
    public R update(@RequestBody ActiveEntity active) {
        activeService.updateById(active);
        return R.ok();
    }

    @PostMapping("/save")
    @ApiOperation("活动保存")
    public R save(@RequestBody ActiveEntity active) {
        if (active.getAid() == null) {
            return R.error("活动id不能为空");
        }
        if (SensitiveWordChecker.containsSensitiveWord(active.getInfo())) {
            activeService.save(active);
            return R.error("活动简介包含敏感词");
        }
        return R.ok();
    }

    @PostMapping("/delete")
    @ApiOperation("评论删除")
    public R delete(@RequestBody Long[] ids) {
        activeService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 查询活动报名人
     *
     * @param activeId
     * @return
     */
    @GetMapping("/userlist")
    @ApiOperation("查询活动报名人员")
    public R userlist(@RequestParam(value = "active_id") Integer activeId) {
        List<AppUserEntity> result = activeService.selectUserByActiveId(activeId);
        return R.ok().put("result", result);
    }
    /**
     * 定时切换轮播图
     */
    @Bean("ChangeSwigger")
    public void ChangeSwigger(){
        System.out.println("123");
    }
}
